from mootdx.quotes import Quotes
from mootdx import consts
from db.save import Save
#market: 市场代码. 0 - 深圳, 1 - 上海 (可以使用常量 MARKET_SZ, MARKET_SH 代替)
client = Quotes.factory(market='std')
save = Save()
conn=save.connect()
cursor = conn.cursor()

symbol = client.stocks(market=consts.MARKET_SH)
for index_value, row_series in symbol.iterrows():
    row_dict = row_series.to_dict()
    row_dict['stock_index']=index_value
    row_dict['market'] = 'SH'
    print(row_dict)
    save.exec(row_dict, "stocklist",conn,cursor)

symbol = client.stocks(market=consts.MARKET_SZ)
for index_value, row_series in symbol.iterrows():
    row_dict = row_series.to_dict()
    row_dict['stock_index']=index_value
    row_dict['market'] = 'SZ'
    print(row_dict)
    save.exec(row_dict, "stocklist",conn,cursor)

cursor.close()
conn.close()
